package ywpt.service.people;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.stereotype.Service;

import ywpt.core.dao.HibernateEntityDao;
import ywpt.model.PeopleFamily;
import ywpt.model.PeopleInfo;
@Service("familyService")
public class FamilyServiceImpl extends HibernateEntityDao<PeopleFamily> implements FamilyService{

	public FamilyServiceImpl(){
		
	}
	@Override
	public PeopleFamily getFamilyInfoById(Long id) {
		return this.get(id);
	}

	@Override
	public int getFamilyInfoCountByCriteria(DetachedCriteria query) {
		return this.getCountByCriteria(query);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<PeopleFamily> getFamilyInfos(DetachedCriteria query,
			int pageSize, int startIndex) {
		return this.findAllByCriteria(query, pageSize, startIndex);
	}

	@Override
	public void removeFamilyInfo(Long id) {
		this.removeById(id);
	}

	@Override
	public void saveFamilyInfo(PeopleFamily familyInfo,Long peopleId) {
		if(peopleId != null){
			familyInfo.setPeople(this.get(PeopleInfo.class, peopleId));
		}
		this.save(familyInfo);
	}

	@Override
	public void updateFamilyInfo(PeopleFamily familyInfo,Long peopleId) {
		if(peopleId != null){
			familyInfo.setPeople(this.get(PeopleInfo.class, peopleId));
		}
		this.update(familyInfo);
	}

}
